package com.aaa.controller.sas;


import com.aaa.controller.BaseController;
import com.aaa.entity.Result;
import com.aaa.entity.sas.PageSortEntity;
import com.aaa.entity.sas.QuestionSas;
import com.aaa.entity.sds.Sds;
import com.aaa.service.sas.QuSasService;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;


/**问题表，表控制层
 * @Auther: wanghuajie
 * @Date: 2022/8/29 20:12
 * @Description:
 */
@RestController
@RequestMapping("/qusas")
public class QuSasController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private QuSasService quSasService;

    /**
     * 去显示所有测试题的页面
     */
    @RequestMapping("toShowSAS.do")
    public ModelAndView toShowSAS(ModelAndView modelAndView){
        modelAndView.setViewName("sas/showSAS");
        return modelAndView;
    }


    /**
     * 分页查询
     *
     * @param questionSas 筛选条件
     * @param questionSas      查询条件对象
     * @return 查询结果
     */
    @RequestMapping("findAllQuestionSAS.do")
    public Result FindAllQuestionSAS(PageSortEntity pageSortEntity, QuestionSas questionSas) {
        List<QuestionSas> questions = quSasService.FindAllQuesTionSAS(pageSortEntity, questionSas);
        Page page = (Page) questions;
        return success(page.getTotal(),page.getResult());
    }

    /**
     * 添加
     * @param questionSas
     * @return
     */
    @RequestMapping("insaertQuestionSAS.do")
    public Result InsaertQuestionSAS(QuestionSas questionSas) {
        int insert = quSasService.insertSas(questionSas);
        if (insert>0){
            return success();

        }else {
            return fail();
        }

    }
    /**
     * 删除
     * @param
     * @return
     */
    @RequestMapping("deleteQuesTionSAS.do")
    public Result deleteQuesTionSAS(int[] id) {
        boolean b = quSasService.deleteQuesTionSAS(id);
        if (b) {
            return super.success();

        }
        return super.fail();
    }
    /**
     * 修改
     * @param questionSas
     * @return
     */
    @RequestMapping("updateQuestionSAS.do")
    public Result updateQuestionSAS(QuestionSas questionSas) {
        questionSas.setUpdateTime(new Date());
        int i = quSasService.updataQuesTionSAS(questionSas);
        if (i>0) {
            return super.success();
        }
        return super.fail();
    }
    /**
     * 查重
     * @param
     * @return
     */
    @GetMapping("repetitionNameSas.do")
        public Result repetitionNameSas(QuestionSas questionSas){
        boolean b = this.quSasService.repetitionNameSas(questionSas);
        if (b){
            return success("问题可用");
        }
        return fail("问题重复，不可用");
    }
    /*
   查询所有，存储题库
    */
    @ResponseBody
    @RequestMapping("questionAllSas.do")
    public String tbl_question_sas(HttpSession session) {
        List<QuestionSas> tbl_question_sas = quSasService.findAllSAS();
        for (QuestionSas tbl_question_sa : tbl_question_sas) {
        }
        session.setAttribute("question", tbl_question_sas);
        return "sasTest";
    }


}


























